/**
 * User: ct/512799311@qq.com
 * Date: 2017/11/10 0010
 * Time: 上午 10:33
 *
 */
import originJSONP from 'jsonp'

export default function jsonp(url, data, option) {
    url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
    console.log(url);
    return new Promise((resolve, reject) => {
        originJSONP(url, option, (err, data) => {
            if (!err) {
                resolve(data)
            } else {
                reject(err)
            }
        })
    })
};

function param(data) {
    let url = ''
    for (var k in data) {

        let value = data[k] != null ? data[k] : ""
        url += '&'+k+"="+encodeURIComponent(value)
    }
    return url ? url.substring(1) : ''
}